﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <title>爆款热销</title>
    <link rel="stylesheet" href="/zhekou/css/common.css" />
    <link rel="stylesheet" href="/zhekou/css/zhekou.css?v=20170317" />
    <script type="text/javascript" src="http://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
    <script type="text/javascript" src="http://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
    <script type="text/javascript" src="/zhekou/js/common.js"></script>
</head>
<body>
    <div class="wrapper zk-collection" style="padding-top:40px;">
        <div class="cate-area">
            <div class="inner">
                <a class="cate-item active" data-tab-index="1" data-cate-id="0">精选</a>
                <a class="cate-item" data-tab-index="2" data-cate-id="1">女装</a>
                <a class="cate-item" data-tab-index="3" data-cate-id="7">母婴</a>
                <a class="cate-item" data-tab-index="4" data-cate-id="6">美妆</a>
                <a class="cate-item" data-tab-index="5" data-cate-id="12">居家百货</a>
                <a class="cate-item" data-tab-index="6" data-cate-id="4">配饰</a>
                <a class="cate-item" data-tab-index="7" data-cate-id="8">美食</a>
                <a class="cate-item" data-tab-index="8" data-cate-id="5">运动</a>
                <a class="cate-item" data-tab-index="9" data-cate-id="13">家电</a>
                <a class="cate-item" data-tab-index="10" data-cate-id="10">数码</a>
                <a class="cate-item" data-tab-index="11" data-cate-id="2">男装</a>
                <a class="cate-item" data-tab-index="12" data-cate-id="9">内衣</a>
                <a class="cate-item" data-tab-index="13" data-cate-id="3">鞋包</a>
                <a class="cate-item" data-tab-index="14" data-cate-id="11">家装</a>
                <a class="cate-item" data-tab-index="15" data-cate-id="14">汽车</a>
                <a class="cate-item" data-tab-index="16" data-cate-id="15">生活服务</a>
                <a class="cate-item" data-tab-index="17" data-cate-id="16">图书音像</a>
                <a class="cate-item" data-tab-index="18" data-cate-id="17">游戏话费</a>
                <a class="cate-item" data-tab-index="19" data-cate-id="64">其它</a>
            </div>
        </div>
        <div class="product-list-area" style="">
            <div class="product-list" id="couponList" style="margin:0;padding:0 0 10px 10px;background-color: #f8f8f8;">
            </div>
            <p class="loading-text">努力加载中...</p>
        </div>
    </div>
    <input type="hidden" id="noDock" value="1" />
    <script type="text/javascript">
        Zepto(function ($) {
            FastClick.attach(document.body);

            var _w = $('.wrapper').width(), picH = (_w - 10 - 5 - 10) / 2;
            if (_w > 500) {
                picH = (_w - 10 - 5 - 5 - 10) / 3;
            }
            $('.product-item-t2').css('width', picH + 'px');
            $('.product-item-t2 .pic').css({ 'width': picH + 'px', 'height': picH + 'px' });
            Util.lazyLoad('lazy');

            var couponList = $('#couponList'), loadingText = $('.loading-text');
            var page = 0, pagesize = 20, load = 1, cate = 0,
                type = 'last', channel = 35, gender = 0;

            $('.product-list-area').css('min-height', (document.documentElement.clientHeight - 40) + 'px');

            var k9TabItem = $('.k9-tab-area .tab-item');
            k9TabItem.on('click', function () {
                var _this = $(this);
                if (!_this.hasClass('active')) {
                    $('.k9-tab-area .tab-item.active').removeClass('active');
                    _this.addClass('active');

                    type = _this.data('type');
                    cate = 0;
                    $('.cate-item.active').removeClass('active');
                    $($('.cate-item')[0]).addClass('active');
                    page = 0;
                    load = 1;
                    loadingText.html('努力加载中...');
                    couponList.html('');
                    $('body').scrollTop(0);
                    setTimeout(getCouponList, 30);
                }
            });

            var cateArea = $('.cate-area'),
                cateAreaInner = $('.cate-area .inner'),
                cateItem = $('.cate-item');
            cateItem.on('click', function () {
                var _this = $(this);
                if (!_this.hasClass('active')) {
                    $('.cate-item.active').removeClass('active');
                    _this.addClass('active');

                    var l = _this.offset().left - cateAreaInner.offset().left;
                    cateAreaInner.scrollLeft(cateAreaInner.scrollLeft() + l - _w / 2 + 20);

                    cate = _this.data('cate-id');
                    page = 0;
                    load = 1;
                    loadingText.html('努力加载中...');
                    couponList.html('');
                    $('body').scrollTop(0);
                    setTimeout(getCouponList, 30);
                }
            });

            getCouponList();

            Util.scrollEvent(getCouponList, 300);

            function getCouponList() {
                if (!load) {
                    return;
                }
                $.ajax({
                    url: '/sale/getZhekouListByCate',
                    type: 'Post',
                    dataType: 'json',
                    data: {
                        'type': type,
                        'limit': page,
                        'pagesize': pagesize,
                        'cid': cate,
                        //'sort': sort,
                        'Key': "",
                        'gender': gender,

                    },
                    beforeSend: function () {
                        load = 0;
                    },
                    success: function (data) {
                        if (data.rows.CurrentPageList != null) {
                            createCouponListHtml(data.rows.CurrentPageList);
                            if (data.rows.CurrentPageList.length >= pagesize) {

                                page++;
                                load = 1;
                            } else {
                                loadingText.html('没有更多了');
                            }
                        } else {
                            loadingText.html('没有更多了');
                        }
                    }
                });
            }

            function createCouponListHtml(clist) {
                var htmlstr = '';
                for (var i = 0, len = clist.length; i < len; i++) {
                    var zk = clist[i];
                    htmlstr += '<a href="/goods/' + zk.auctionId + '.html">';
                    htmlstr += '<div class="product-item-t2" style="width:' + picH + 'px;">';
                    htmlstr += '<div class="pic lazy new" data-original="' + zk.pictUrl + '" style="width: ' + picH + 'px; height: ' + picH + 'px;"></div>';
                    htmlstr += '<p class="title">';
                    //if (type == 'brand' && zk.brand.brand_id) {
                    //htmlstr += '<span class="brand">' + zk.brand.name + '</span>';
                    // } else if (zk.post_free == 1) {
                    htmlstr += '<span class="post-free">包邮</span>&nbsp;';
                    //}
                    htmlstr += zk.title + '</p>';
                    if (type == 'speed') {
                        htmlstr += '<div class="progress-area">';
                        htmlstr += '<p class="pro-text">已领' + Math.floor(0.98 * 100) + '%</p>';
                        htmlstr += '<div class="pro-container">';
                        htmlstr += '<div data-pro="' + zk.progress + '" class="pro" style="width:' + Math.floor(0.98 * 100) + '%;"></div>';
                        htmlstr += '</div>';
                        htmlstr += '</div>';
                    } else {
                        htmlstr += '<p class="sold">' + (zk.platform_id == 2 ? '淘宝' : '天猫') + '价&nbsp;&yen;' + zk.zkPrice + '</p>';
                    }
                    htmlstr += '<div class="price-area">';
                    htmlstr += '<p class="gap-price"><em class="number-font">' + zk.couponAmount + '</em>元券</p>';
                    htmlstr += '<p class="price">券后价&yen;<em class="number-font">' + (zk.zkPrice - zk.couponAmount).toFixed(2) + '</em></p>';
                    htmlstr += '</div>';
                    htmlstr += '</div>';
                    htmlstr += '</a>';
                }
                couponList.append(htmlstr);
                Util.lazyLoad('lazy.new');
                $('.lazy.new').removeClass('new');
            }

            var countdown = function (obj, endDesc) {
                if (!obj) {
                    return;
                }
                obj = $(obj);
                var endTime = obj.data('endtime');
                var now = Math.floor(new Date().getTime() / 1000) * 1;
                if (now > endTime) {
                    obj.html(endDesc);
                } else {
                    var gap = endTime - now;
                    var dd = Math.floor(gap / (60 * 60 * 24));
                    var hh = Math.floor((gap - dd * 60 * 60 * 24) / (60 * 60));
                    var mm = Math.floor((gap - dd * 60 * 60 * 24 - hh * 60 * 60) / 60);
                    var ss = gap - dd * 60 * 60 * 24 - hh * 60 * 60 - mm * 60;
                    var timeStr = '距结束&nbsp;'
                        + (hh > 0 ? '<em>' + (hh >= 10 ? hh : '0' + hh) + '</em>:' : '')
                        + (mm > 0 ? '<em>' + (mm >= 10 ? mm : '0' + mm) + '</em>:' : '')
                        + (ss >= 0 ? '<em>' + (ss >= 10 ? ss : '0' + ss) + '</em>' : '');
                    obj.html(timeStr);
                }
            }
            if ($('.count-down').length > 0) {
                countdown($('.count-down'), '已结束');
                setInterval(function () {
                    countdown($('.count-down'), '已结束');
                }, 1000);
            }
        });
        function callbackHandler() { }
    </script>

</body>
</html>